package com.example.service;

import com.example.dao.MoneyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @Author: wyp
 * @Date: 2021/9/2 16:52
 */
@Service
public class MoneyService {

    @Autowired
    private MoneyDao moneyDao;

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED,isolation = Isolation.REPEATABLE_READ)
    public void transferOfAccount(Integer from, Integer to, BigDecimal money){
        moneyDao.reduceMoney(from,money);
        //模拟异常
//        int i = 1/0;
        moneyDao.addMoney(to,money);
    }
}
